<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>标签 | minigame-canvas-engine</title>
    <meta name="description" content="轻量级canvas渲染引擎">
    <meta name="generator" content="VuePress 1.3.1">
    <meta name="robots" content="all">
  <meta name="author" content="yuanzm">
  <meta name="keywords" content="minigame-canvans-engine, minigame, canvas, engine, game engine">
    
    <link rel="preload" href="/minigame-canvas-engine/assets/css/0.styles.cc9e188e.css" as="style"><link rel="preload" href="/minigame-canvas-engine/assets/js/app.34da408a.js" as="script"><link rel="preload" href="/minigame-canvas-engine/assets/js/2.b58d2eb8.js" as="script"><link rel="preload" href="/minigame-canvas-engine/assets/js/9.b0c2371a.js" as="script"><link rel="prefetch" href="/minigame-canvas-engine/assets/js/10.525d02f5.js"><link rel="prefetch" href="/minigame-canvas-engine/assets/js/3.65046f77.js"><link rel="prefetch" href="/minigame-canvas-engine/assets/js/4.e50764d8.js"><link rel="prefetch" href="/minigame-canvas-engine/assets/js/5.aa96439f.js"><link rel="prefetch" href="/minigame-canvas-engine/assets/js/6.8bafe2e6.js"><link rel="prefetch" href="/minigame-canvas-engine/assets/js/7.6ddd2960.js"><link rel="prefetch" href="/minigame-canvas-engine/assets/js/8.5202cd3c.js">
    <link rel="stylesheet" href="/minigame-canvas-engine/assets/css/0.styles.cc9e188e.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container"><header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/minigame-canvas-engine/" class="home-link router-link-active"><!----> <span class="site-name">minigame-canvas-engine</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"> <a href="https://github.com/wechat-miniprogram/minigame-canvas-engine" target="_blank" rel="noopener noreferrer" class="repo-link">
    GitHub
    <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></nav></div></header> <div class="sidebar-mask"></div> <aside class="sidebar"><nav class="nav-links"> <a href="https://github.com/wechat-miniprogram/minigame-canvas-engine" target="_blank" rel="noopener noreferrer" class="repo-link">
    GitHub
    <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></nav>  <ul class="sidebar-links"><li><a href="/minigame-canvas-engine/" class="sidebar-link">概览</a></li><li><section class="sidebar-group depth-0"><a href="/minigame-canvas-engine/api/guide" class="sidebar-heading clickable open"><span>文档</span> <!----></a> <ul class="sidebar-links sidebar-group-items"><li><a href="/minigame-canvas-engine/api/guide.html" class="sidebar-link">快速入门</a></li><li><a href="/minigame-canvas-engine/api/api.html" class="sidebar-link">API</a></li><li><a href="/minigame-canvas-engine/api/tags.html" class="active sidebar-link">标签</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/minigame-canvas-engine/api/tags.html#标签列表" class="sidebar-link">标签列表</a></li><li class="sidebar-sub-header"><a href="/minigame-canvas-engine/api/tags.html#公共属性" class="sidebar-link">公共属性</a></li><li class="sidebar-sub-header"><a href="/minigame-canvas-engine/api/tags.html#view标签" class="sidebar-link">view标签</a></li><li class="sidebar-sub-header"><a href="/minigame-canvas-engine/api/tags.html#image标签" class="sidebar-link">image标签</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/minigame-canvas-engine/api/tags.html#特殊属性" class="sidebar-link">特殊属性</a></li></ul></li><li class="sidebar-sub-header"><a href="/minigame-canvas-engine/api/tags.html#text标签" class="sidebar-link">text标签</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/minigame-canvas-engine/api/tags.html#特殊属性-2" class="sidebar-link">特殊属性</a></li><li class="sidebar-sub-header"><a href="/minigame-canvas-engine/api/tags.html#特殊样式" class="sidebar-link">特殊样式</a></li></ul></li><li class="sidebar-sub-header"><a href="/minigame-canvas-engine/api/tags.html#scrollview标签" class="sidebar-link">scrollview标签</a></li><li class="sidebar-sub-header"><a href="/minigame-canvas-engine/api/tags.html#bitmapfont" class="sidebar-link">bitmapfont</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/minigame-canvas-engine/api/tags.html#特殊样式-2" class="sidebar-link">特殊样式</a></li><li class="sidebar-sub-header"><a href="/minigame-canvas-engine/api/tags.html#示例" class="sidebar-link">示例</a></li></ul></li></ul></li><li><a href="/minigame-canvas-engine/api/style.html" class="sidebar-link">样式</a></li></ul></section></li></ul> </aside> <main class="page"> <div class="theme-default-content content__default"><h1 id="标签"><a href="#标签" class="header-anchor">#</a> 标签</h1> <h2 id="标签列表"><a href="#标签列表" class="header-anchor">#</a> 标签列表</h2> <table><thead><tr><th>标签</th> <th>说明</th></tr></thead> <tbody><tr><td>view</td> <td>容器标签，与HTML中的div相似</td></tr> <tr><td>scrollview</td> <td>滚动列表容器，如果容器内的子元素高度大于scrollview高度，支持纵向滚动，不支持嵌套scrollview</td></tr> <tr><td>image</td> <td>图片标签，</td></tr> <tr><td>text</td> <td>文本标签</td></tr> <tr><td>bitmaptext</td> <td>bitmapfont文本标签</td></tr></tbody></table> <h2 id="公共属性"><a href="#公共属性" class="header-anchor">#</a> 公共属性</h2> <p>每个标签都会通过属性来支持一些特有的功能，下面列举所有标签都会有的属性。</p> <table><thead><tr><th>属性</th> <th>类型</th> <th>是否必填</th> <th>说明</th></tr></thead> <tbody><tr><td>id</td> <td>string</td> <td>否</td> <td>非唯一标识，两个标签可以共用id</td></tr> <tr><td>class</td> <td>string</td> <td>否</td> <td>与浏览器相同</td></tr></tbody></table> <h2 id="view标签"><a href="#view标签" class="header-anchor">#</a> view标签</h2> <p>view标签用来页面布局，布局严格遵循<a href="https://developer.mozilla.org/en-US/docs/Web/CSS/flex" target="_blank" rel="noopener noreferrer">CSS Flex布局<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a>，节点在Flex属性相互作用的结果可以通过Yoga的<a href="https://yogalayout.com/playground" target="_blank" rel="noopener noreferrer">Playground<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a>试验。</p> <h2 id="image标签"><a href="#image标签" class="header-anchor">#</a> image标签</h2> <h3 id="特殊属性"><a href="#特殊属性" class="header-anchor">#</a> 特殊属性</h3> <table><thead><tr><th>属性</th> <th>类型</th> <th>是否必填</th> <th>说明</th></tr></thead> <tbody><tr><td>src</td> <td>string</td> <td>是</td> <td>图片链接</td></tr></tbody></table> <div class="custom-block tip"><p class="custom-block-title">TIP</p> <p>1.小游戏开放数据域场景图片路径不需要加./作为前缀，以小游戏根目录作为根目录；</p> <p>2.图片可以通过API<a href="/minigame-canvas-engine/api/api.html#loadimgs">loadImgs</a>实现预加载</p></div> <h2 id="text标签"><a href="#text标签" class="header-anchor">#</a> text标签</h2> <h3 id="特殊属性-2"><a href="#特殊属性-2" class="header-anchor">#</a> 特殊属性</h3> <table><thead><tr><th>属性</th> <th>类型</th> <th>是否必填</th> <th>说明</th></tr></thead> <tbody><tr><td>value</td> <td>string</td> <td>是</td> <td>文字内容</td></tr></tbody></table> <h3 id="特殊样式"><a href="#特殊样式" class="header-anchor">#</a> 特殊样式</h3> <table><thead><tr><th>属性</th> <th>类型</th> <th>是否必填</th> <th>说明</th></tr></thead> <tbody><tr><td>textOverflow</td> <td>string</td> <td>否</td> <td>文字溢出处理方式，默认不处理，ellipsis则支持自动截断</td></tr> <tr><td>textAlign</td> <td>string</td> <td>否</td> <td>文字水平居中方式，默认left，支持right、center</td></tr></tbody></table> <h2 id="scrollview标签"><a href="#scrollview标签" class="header-anchor">#</a> scrollview标签</h2> <p>滚动内容的容器，滚动的前提是正确调用<a href="/minigame-canvas-engine/api/api.html#updateviewport">updateViewPort</a></p> <h2 id="bitmapfont"><a href="#bitmapfont" class="header-anchor">#</a> bitmapfont</h2> <p>在游戏开发里面，为了更好的视觉效果，经常要将一些常用文字经过设计成图片，然后打包成特殊的字体，称为BitmapFont，基本上所有的游戏引擎都支持了这种技术。</p> <p>本渲染引擎调研了常见的H5游戏引擎Laya、Cocos、Egret，他们普遍支持<a href="https://www.angelcode.com/products/bmfont/" target="_blank" rel="noopener noreferrer">AngelCode.com<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a>打包后的配置文件规范，因此biamapfont
同样只支持通过该工具打包后的文件。</p> <p>需要特别注意的是，对于一般的游戏引擎而言，都会在自己的IDE里面将.fnt打包进代码里面，这里为了引擎轻量化，需要通过API<a href="/minigame-canvas-engine/api/api.html#registbitmapfont">registBitMapFont</a>手动注册字体。
然后在标签里面通过font属性声明需要使用的字体。</p> <div class="language-html extra-class"><pre class="language-html"><code><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>bitmaptext</span> <span class="token attr-name">font</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">&quot;</span>fnt_number-export<span class="token punctuation">&quot;</span></span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">&quot;</span>title<span class="token punctuation">&quot;</span></span> <span class="token attr-name">value</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">&quot;</span>等级<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>bitmaptext</span><span class="token punctuation">&gt;</span></span>
</code></pre></div><div class="language-js extra-class"><pre class="language-js"><code>title<span class="token operator">:</span> <span class="token punctuation">{</span>
        width<span class="token operator">:</span> <span class="token number">144</span><span class="token punctuation">,</span>
        fontSize<span class="token operator">:</span> <span class="token number">48</span><span class="token punctuation">,</span>
        height<span class="token operator">:</span> <span class="token number">120</span><span class="token punctuation">,</span>
        lineHeight<span class="token operator">:</span> <span class="token number">50</span><span class="token punctuation">,</span>
        textAlign<span class="token operator">:</span> <span class="token string">'center'</span><span class="token punctuation">,</span>
      	verticalAlign<span class="token operator">:</span> <span class="token string">'top'</span><span class="token punctuation">,</span>
        fontWeight<span class="token operator">:</span> <span class="token string">'bold'</span><span class="token punctuation">,</span>
        borderBottomWidth<span class="token operator">:</span> <span class="token number">6</span><span class="token punctuation">,</span>
        borderColor<span class="token operator">:</span> <span class="token string">'#000000'</span><span class="token punctuation">,</span>
<span class="token punctuation">}</span>

</code></pre></div><h3 id="特殊样式-2"><a href="#特殊样式-2" class="header-anchor">#</a> 特殊样式</h3> <table><thead><tr><th>属性</th> <th>类型</th> <th>是否必填</th> <th>说明</th></tr></thead> <tbody><tr><td>width</td> <td>Number</td> <td>是</td> <td>文字的容器宽度，当width大于文字实际绘制占据的宽度，textAlign生效</td></tr> <tr><td>height</td> <td>Number</td> <td>是</td> <td>文字的容器高度，当height大于lineHeight，verticalAlign属性生效</td></tr> <tr><td>lineHeight</td> <td>Number</td> <td>否</td> <td>渲染文字的行高，默认为配置文件里面的lineHeight</td></tr> <tr><td>textAlign</td> <td>String</td> <td>否</td> <td>文字水平居中方式，默认left，支持right、center</td></tr> <tr><td>verticalAlign</td> <td>String</td> <td>否</td> <td>文字垂直居中的方式，默认为middle，支持top和bottom</td></tr></tbody></table> <h3 id="示例"><a href="#示例" class="header-anchor">#</a> 示例</h3> <img src="/minigame-canvas-engine/imgs/bitmapfont.png" width="400"></div> <footer class="page-edit"><div class="edit-link"><a href="https://github.com/wechat-miniprogram/minigame-canvas-engine/edit/master/api/tags.md" target="_blank" rel="noopener noreferrer">在 GitHub 上编辑此页</a> <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></div> <div class="last-updated"><span class="prefix">上次更新:</span> <span class="time">3/15/2020, 11:28:23 PM</span></div></footer> <div class="page-nav"><p class="inner"><span class="prev">
      ←
      <a href="/minigame-canvas-engine/api/api.html" class="prev">
        API
      </a></span> <span class="next"><a href="/minigame-canvas-engine/api/style.html">
        样式
      </a>
      →
    </span></p></div> </main></div><div class="global-ui"></div></div>
    <script src="/minigame-canvas-engine/assets/js/app.34da408a.js" defer></script><script src="/minigame-canvas-engine/assets/js/2.b58d2eb8.js" defer></script><script src="/minigame-canvas-engine/assets/js/9.b0c2371a.js" defer></script>
  </body>
</html>
